Namespace Actions.ActionItems
    <ActionItemWordAttribute("text")> _
    Public Class aiTextOutput
        Inherits Actions.ActionItem

        Public OutputFileName As String = "info.txt"
        Public Append As Boolean = True
        Public Contents As String
        Public Encoding As System.Text.Encoding = System.Text.Encoding.Unicode

        Public Sub New(ByVal Owner As Action, ByVal Definition As Xml.XmlNode)
            MyBase.New(Owner, Definition)
        End Sub

        Public Overrides Sub Execute()
            Contents = OwnerAction.InsertParams(Configuration.Text)
            OutputFileName = OwnerAction.InsertParams(Configuration.Attribute("to", OutputFileName))
            OutputFileName = OwnerAction.Info.ResultsFolderName + "\" + OutputFileName
            Append = Configuration.BoolAttribute("append", Append)

            Dim LeadingTabFilter As New System.Text.RegularExpressions.Regex("$\t+")
            Contents = LeadingTabFilter.Replace(Contents, "")

            Try
                Dim f As New IO.StreamWriter(OutputFileName, Append, Encoding)
                f.WriteLine(Contents)
                f.Close()
            Catch ex As Exception
                LogException(ex)
            End Try
        End Sub
    End Class
End Namespace

